package physicsSimTest;

public class Vector {
	double x;
	double y;
	public static final Vector ZERO = new Vector(0, 0);
	
	public Vector(double xV, double yV){
		x = xV;
		y = yV;
	}
	
	public static double getMagnitude(Vector v){return Math.sqrt(v.x*v.x+v.y*v.y);}
	
	public static double getAngle(Vector v){return Math.atan2(v.y, v.x);}
	
	public static Vector scalarMultiply(double s, Vector v){return new Vector(v.x*s, v.y*s);}
	
	public static Vector add(Vector v1, Vector v2){return new Vector(v1.x+v2.x, v1.y+v2.y);}
	public static Vector subtract(Vector v1, Vector v2){return new Vector(v1.x-v2.x, v1.y-v2.y);}
	
	public static double dotProduct(Vector v1, Vector v2){return (v1.x*v2.x+v1.y*v2.y);}
	public Vector projectOnto(Vector v2){
		double scalar = dotProduct(this, v2)/Math.pow(Vector.getMagnitude(v2), 2);
		return Vector.scalarMultiply(scalar, v2);
	}
	
	public static Vector normal(Vector v){
		return scalarMultiply(1/getMagnitude(v), v);
	}
	
	public String toString(){
		return "<"+x+", "+y+">";
	}
	
	public boolean equals(Vector other){
		return (x==other.x&&y==other.y);
	}

	public static Vector copy(Vector v) {
		return new Vector(v.x, v.y);
	}
}
